package com.finer.service.impl;

import com.finer.entity.buy.FinerBuyBackRequestGoods;
import com.finer.dao.FinerBuyBackRequestGoodsDao;
import com.finer.service.FinerBuyBackRequestGoodsService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 采购退货申请与商品关联表(FinerBuyBackRequestGoods)表服务实现类
 *
 * @author makejava
 * @since 2024-10-21 10:20:37
 */
@Service("finerBuyBackRequestGoodsService")
public class FinerBuyBackRequestGoodsServiceImpl implements FinerBuyBackRequestGoodsService {
    @Resource
    private FinerBuyBackRequestGoodsDao finerBuyBackRequestGoodsDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public FinerBuyBackRequestGoods queryById(Integer id) {
        return this.finerBuyBackRequestGoodsDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param finerBuyBackRequestGoods 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<FinerBuyBackRequestGoods> queryByPage(FinerBuyBackRequestGoods finerBuyBackRequestGoods, PageRequest pageRequest) {
        long total = this.finerBuyBackRequestGoodsDao.count(finerBuyBackRequestGoods);
        return new PageImpl<>(this.finerBuyBackRequestGoodsDao.queryAllByLimit(finerBuyBackRequestGoods, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param finerBuyBackRequestGoods 实例对象
     * @return 实例对象
     */
    @Override
    public FinerBuyBackRequestGoods insert(FinerBuyBackRequestGoods finerBuyBackRequestGoods) {
        this.finerBuyBackRequestGoodsDao.insert(finerBuyBackRequestGoods);
        return finerBuyBackRequestGoods;
    }

    /**
     * 修改数据
     *
     * @param finerBuyBackRequestGoods 实例对象
     * @return 实例对象
     */
    @Override
    public FinerBuyBackRequestGoods update(FinerBuyBackRequestGoods finerBuyBackRequestGoods) {
        this.finerBuyBackRequestGoodsDao.update(finerBuyBackRequestGoods);
        return this.queryById(finerBuyBackRequestGoods.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.finerBuyBackRequestGoodsDao.deleteById(id) > 0;
    }
}
